<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/16
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑汉字用户</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="/static//css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="/static//css/style.min.css?v=4.1.0" rel="stylesheet">
</head>
<body>
<div style="padding: 15px;">
    <table class="table">
        <tr>
            <td width="80">用户名</td>
            <td><input type="text" class="form-control" name="username" placeholder="请输入用户名" value="四川资阳1"></td>
        </tr>
        <tr>
            <td>手机号</td>
            <td><input type="text" class="form-control" name="tel" placeholder="请输入手机号" value="zy1"></td>
        </tr>
        <tr>
            <td>身份证</td>
            <td><input type="text" class="form-control" name="card" placeholder="请输入身份证" value="312313"></td>
        </tr>
        <tr>
            <td>学习科目</td>
            <td><input type="text" class="form-control" name="studysub" placeholder="请输入学习科目" value="科一  科四"></td>
        </tr>
        <tr>
            <td>用户地址</td>
            <td><input type="text" class="form-control" name="place" placeholder="请输入用户地址" value="四川资阳"></td>
        </tr>
        <tr>
            <td>缴纳学费</td>
            <td><input type="text" class="form-control" name="money" placeholder="请输入缴纳学费" value="2431"></td>
        </tr>
        <tr>
            <td>驾校名称</td>
            <td><input type="text" class="form-control" name="drivename" placeholder="请输入驾校名称" value="斑马线"></td>
        </tr>

        <tr>
            <td>使用期限</td>
            <td>
                <div  id="data_1">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" class="form-control etime" name='timelimit' readonly placeholder="请选择会员到期时间" value="2018-06-05">
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <button class="btn btn-primary btn-lg btn-block" onclick="AjaxForm()">提交保存</button>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/content.min.js?v=1.0.0"></script>
<script src="/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="/static/js/plugins/cropper/cropper.min.js"></script>
<script src="/static/js/demo/form-advanced-demo.min.js"></script>

<script>
    /*var url = location.search.split("&", 2);
    var id = url[0].substr(4);
    var type = url[1].substr(5);*/
    var url = location.search;

    $(".etime").datepicker({format: 'yyyy-mm-dd',minView:2,autoclose:true,language: 'zh-CN'});
    function AjaxForm() {
        var username=$('input[name=username]').val(),
            tel=$('input[name=tel]').val(),
            card=$('input[name=card]').val(),
            studysub=$('input[name=studysub]').val(),
            place=$('input[name=place]').val(),
            money=$('input[name=money]').val(),
            drivename=$('input[name=drivename]').val(),
            timelimit=$('input[name=timelimit]').val(),
            id = url.slice(4),
        data;
        if(timelimit){
            var dateArr = timelimit.split("-");
            var d = new Date();
            d.setFullYear(1*dateArr[0]);
            d.setMonth(1*dateArr[1]-1);
            d.setDate(1*dateArr[2]);
            d.setHours(0);
            d.setMinutes(0);
            d.setSeconds(0);
            d.setMilliseconds(0);
            timelimit=""+(d.getTime()/1000);
        }
      //  console.info(id);
        if(!id){
            layer.msg('参数错误，请重新打开',{icon : 2,time:1000});
            setTimeout(function(){parent.location.reload();},1000);
            return false;
        }
        if(!username){
            layer.msg('请输入用户名',{icon : 2,time:1000});
            $('input[name=username]').focus();
            return false;
        }
        if(!tel){
            layer.msg('请输入手机号',{icon : 2,time:1000});
            $('input[name=tel]').focus();
            return false;
        }
        if(!card){
            layer.msg('请输入身份证',{icon : 2,time:1000});
            $('input[name=card]').focus();
            return false;
        }
        if(!studysub){
            layer.msg('请输入学习科目',{icon : 2,time:1000});
            $('input[name=studysub]').focus();
            return false;
        }
        if(!place){
            layer.msg('请输入用户地址',{icon : 2,time:1000});
            $('input[name=place]').focus();
            return false;
        }
        if(!money){
            layer.msg('请输入缴纳学费',{icon : 2,time:1000});
            $('input[name=money]').focus();
            return false;
        }
        if(!drivename){
            layer.msg('请输入驾校名称',{icon : 2,time:1000});
            $('input[name=drivename]').focus();
            return false;
        }
        if(!timelimit){
            layer.msg('请选择会员到期时间',{icon : 2,time:1000});
            $('input[name=timelimit]').focus();
            return false;
        }
        data={id:id,username:username,tel:tel,card:card,studysub:studysub,place:place,money:money,drivename:drivename,timelimit:timelimit};
        $.ajax({
            type     : 'PUT',
            url      : "/user",
            data     : data,
            dataType : 'json',
            success  : function(json){
                if(json.status=="success"){
                    layer.msg('修改成功',{icon: 1,time:1000});
                    setTimeout(function() {
                        var ind = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(ind)
                        parent.location.reload();
                    },1000);
                }else{
                    layer.msg('修改失败',{icon: 2,time:1000});
                }
            },
            error    : function(){
                layer.msg('服务器繁忙，请刷新页面后重试',{icon: 5,time:1000});
            }
        });
    }

</script>
</body>
</html>
